import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/controller/user.dart';
import 'package:ichinesereader/widgets/dialogs/searchDialog.dart';
import 'package:ichinesereader/widgets/dialogs/switchChildDialog.dart';

class FloatingActionButtonsParentSwitchChild extends StatelessWidget {
  FloatingActionButtonsParentSwitchChild({
    Key? key,
  }) : super(key: key);
  final BooksController _controller = Get.find();
  final String readingTypeFrom = 'leveled';

  Widget build(BuildContext context) {
    final UserController _userController = Get.find();
    var filteredOptions = _userController.parentChildren.where((element) =>
        element.classResps != null && element.classResps!.isNotEmpty);
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Visibility(
          visible: filteredOptions.isNotEmpty && filteredOptions.length > 1,
          child: SizedBox(
            height: 45,
            width: 45,
            child: FloatingActionButton(
              backgroundColor: Theme.of(context).primaryColorDark,
              foregroundColor: Get.isDarkMode
                  ? Colors.black
                  : Theme.of(context).primaryColorLight,
              tooltip: 'Switch Child'.tr,
              heroTag: 'switchclass8899000',
              onPressed: () {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return SwitchParentChildDialog();
                    });
              },
              child: Icon(
                Icons.people_alt_rounded,
                color:
                    Get.isDarkMode ? Colors.black : Get.theme.primaryColorLight,
                size: 24,
              ),
            ),
          ),
        ),
        SizedBox(height: 12),
        if (Get.currentRoute == '/parent/leveledreadings')
          SizedBox(
            width: 45.0,
            height: 45.0,
            child: FloatingActionButton(
              backgroundColor: Theme.of(context).primaryColorDark,
              foregroundColor: Get.isDarkMode
                  ? Colors.black
                  : Theme.of(context).primaryColorLight,
              heroTag: Text('SearchBooks88888899999'.tr),
              tooltip: 'Search Books'.tr,
              onPressed: () {
                List<String> bookids = [];
                _controller.selectedLeveledReadingBookItems.forEach(
                  (element) {
                    if (!bookids.contains(element.bookId))
                      bookids.add(element.bookId.toString());
                  },
                );
                showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return SearchDialog(
                          readingType: NanhaiBookReadingTypes.leveled,
                          title: 'Search Books'.tr,
                          selected: bookids,
                          message: '',
                          readingTypeFrom: readingTypeFrom);
                    });
              },
              child: Icon(
                Icons.search,
                color:
                    Get.isDarkMode ? Colors.black : Get.theme.primaryColorLight,
                size: 24,
              ),
              elevation: 5,
              splashColor: Colors.grey,
            ),
          ),
        SizedBox(height: 12),
        SizedBox(
          height: 45,
          width: 45,
          child: FloatingActionButton(
            heroTag: 'balbalhome88990000',
            backgroundColor: Theme.of(context).primaryColorDark,
            foregroundColor: Get.isDarkMode
                ? Colors.black
                : Theme.of(context).primaryColorLight,
            tooltip: 'Home Page'.tr,
            onPressed: () {
              Get.delete<ReportsController>();
              Get.offAndToNamed('/parent/home');
            },
            child: Icon(
              Icons.home_outlined,
              color:
                  Get.isDarkMode ? Colors.black : Get.theme.primaryColorLight,
              size: 24,
            ),
          ),
        ),
      ],
    );
  }
}
